#include <bits/stdc++.h>
using namespace std;

const int N = 100010;

int n, m, L, V;
int p[N];

struct car
{
    int l, r;

    bool operator < (const car &T) const
    {
        return l < T.l;
    }
}c[N];

int main ()
{
    freopen ("detect.in", "r", stdin);
    freopen ("detect.out", "w", stdout);

    int T;
    scanf ("%d", &T);
    while (T -- )
    {
        int t = 0, cnt = 0;
        bool flag = true, st = true;
        scanf ("%d%d%d%d", &n, &m, &L, &V);
        for (int i = 1; i <= n; i ++ )
        {
            int d, v, a, l, r;
            scanf ("%d%d%d", &d, &v, &a);
            if (a != 0) flag = false;
            if (a < 0) st = false;
            if (v > V)
            {
                l = d;
                if (a >= 0) r = L;
                else
                {
                    a = -a;
                    int x = (v * v - V * V - 1) / (2 * a);
                    r = min (L, l + x);
                }
            }
            else
            {
                if (a <= 0) continue;

                l = d + (V * V - v * v) / (2 * a) + 1;
                if (l > L) continue;
                r = L;
            }

            c[ ++ t] = {l, r};

        }

        for (int i = 1; i <= m; i ++ ) scanf ("%d", p + i);
        sort (p + 1, p + 1 + m);
        p[m + 1] = 0x3f3f3f3f;
        for (int i = 1; i <= t; i ++ )
        {
            int l = lower_bound (p + 1, p + 2 + m, c[i].l) - p,
                r = upper_bound (p + 1, p + 2 + m, c[i].r) - p;
            if (l != r) c[i - cnt] = c[i];
            else cnt ++;
        }
        n = t - cnt;
        sort (c + 1, c + 1 + n);

        if (flag) printf ("%d %d\n", n, m - 1);
        else if (st) printf ("%d %d\n", n, m - 1);
        else
        {
            int r = c[1].r, res = 0, idx = 0;
            for (int i = 2; i <= n; i ++ )
            {
                if (c[i].l <= p[idx] && c[i].r >= p[idx]) continue;


            }
        }
    }

    return 0;
}
